package com.lotusfall.controller;

import com.github.pagehelper.PageInfo;
import com.lotusfall.pojo.HouseResource;
import com.lotusfall.service.HouseResourceService;
import com.lotusfall.vo.WebResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@Controller
public class HouseResourcesController {
    @Autowired
    HouseResourceService houseResourceService;

    @RequestMapping("/houseResource/save")
    @PostMapping
    public ResponseEntity<Void> save(@RequestBody HouseResource houseResource){
        try{
            int i = this.houseResourceService.saveHouseResources(houseResource);
            if(i == 1){
                return ResponseEntity.status(HttpStatus.CREATED).build();
            }
        }catch (Exception e ){
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    @RequestMapping("/houseResource/queryHouseList")
    @GetMapping
    @ResponseBody
    public WebResult queryHouseList(Integer page,Integer pageSize){
        PageInfo<HouseResource> houseResourcePageInfo = this.houseResourceService.queryHouseList(page,pageSize);
        List<HouseResource> list = houseResourcePageInfo.getList();
        return WebResult.ok(list);
    }


    @RequestMapping("/houseResource/queryHouseListByNum")
    @GetMapping
    @ResponseBody
    public WebResult queryHouseListByNum(Integer page,Integer pageSize,Integer type,Integer ori,Integer area,Integer rent){
        PageInfo<HouseResource> houseResourcePageInfo = this.houseResourceService.queryHouseListByNum(page,pageSize,type,ori,area,rent);
        List<HouseResource> list = houseResourcePageInfo.getList();
        return WebResult.ok(list);
    }
}
